/*******************************************************************************
 * Copyright (c) 2008 Smart Mai(smardio@gmail.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Smart Mai(smardio@gmail.com) - initial API and implementation
 ******************************************************************************/
package com.smartdio.company.views;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import com.smartdio.company.Activator;
import com.smartdio.company.Resources;
import com.smartdio.company.model.Company;
import com.smartdio.company.model.Department;

/**
 * @author smart
 * 
 */
public class CompanyLabelProvider extends LabelProvider implements
		ITableLabelProvider {

	/**
	 * 
	 */
	public CompanyLabelProvider() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
	 * .Object, int)
	 */
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		if(columnIndex!=0)return null;
		if(element instanceof Company){
			return Activator.getDefault().getImage(Resources.OBJ_COMPANY);
		}
		if (element instanceof Department) {
			return Activator.getDefault().getImage(Resources.OBJ_DEPARTMENT);
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
	 * .Object, int)
	 */
	@Override
	public String getColumnText(Object element, int columnIndex) {

		if (element instanceof Company) {
			return getCompanyText((Company) element, columnIndex);
		}
		if (element instanceof Department) {
			return getDepartmentText((Department) element, columnIndex);
		}
		return null;
	}

	private String getCompanyText(Company company, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return company.name;
		case 1:
			return company.description;
		}
		return company.name;
	}

	private String getDepartmentText(Department depart, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return depart.name;
		case 1:
			return depart.description;
		}
		return depart.name;

	}

	@Override
	public Image getImage(Object element) {
		return getColumnImage(element, 0);
	}

	@Override
	public String getText(Object element) {
		return getColumnText(element, 0);
	}

}
